package servlet;

import listener.a;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name = req.getParameter("name");
        String password = req.getParameter("password");
        String sure_password = req.getParameter("sure_password");
        String size1 = req.getParameter("size1");
        String size2 = req.getParameter("size2");
        String size = null;
        if(size1 == null){
            size = size2;
        }
        else {
            size = size1;
        }
        String youname = req.getParameter("youname");
        String email = req.getParameter("email");
        String city = req.getParameter("city");
        String birthday = req.getParameter("birthday");
        String school = req.getParameter("school");

        PrintWriter out = resp.getWriter();

        out.println(name);
        out.println(password);
        out.println(sure_password);
        out.println(size);
        out.println(youname);
        out.println(email);
        out.println(city);
        out.println(birthday);
        out.println(school);




        a a = new a();
        a.test();
        File file = new File(a.filePath);


        InputStream fis = new FileInputStream(file);
        Properties prop = new Properties();
        prop.load(fis);

        String num = prop.getProperty("num");
        //把数字加1
        String s = Integer.toString(Integer.parseInt(num) + 1);

        prop.setProperty("name"+s, name);
        prop.setProperty("password"+s, password);
        prop.setProperty("num", s);

        OutputStream fos = new FileOutputStream(file);
        prop.store(fos, name);

//        prop.store(fos, password);
    }



    }

